import request from '@/utils/request'
const API_PREFIX = '/api/v1/dept'

import { Dept } from './types.ts'
import { Option } from '@/api/types.ts'

/**
 * 获取部门列表
 * @param params
 * @returns
 */
export const getDeptList = (params: Dept.Query) => {
    return request.get<Dept.Row[]>(`${API_PREFIX}/list`, { params })
}

/**
 * 获取部门下拉列表
 * @returns
 */
export const getDeptOptions = () => {
    return request.get<Option[]>(`${API_PREFIX}/options`)
}
/**
 * 获取部门表单详情
 * @param deptId
 * @returns
 */
export const getDeptForm = (deptId: number) => {
    return request.get<Dept.Form>(`${API_PREFIX}/${deptId}/form`)
}

/**
 *  保存部门信息
 * @param params
 */
export const saveDept = (params: Dept.Form) => {
    return request.post(`${API_PREFIX}`, params)
}

/**
 *  更新部门信息
 * @param params
 * @returns
 */
export const updateDept = (params: Dept.Form) => {
    return request.put(`${API_PREFIX}/${params.id}`, params)
}

/**
 *  删除部门信息
 * @param ids 多个ID以英文逗号, 分割
 * @returns
 */
export const deleteDept = (ids: string) => {
    return request.delete(`${API_PREFIX}/${ids}`)
}
